<template>
	<view :style="themeColor">
		<view class="page">
			<view class="flex benben-position-layout flex flex-wrap align-center personalData_flex_0"
				:style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
				<view class='flex flex-wrap align-center justify-between flex-sub personalData_fd0_0'>
					<view class='flex flex-wrap align-center personalData_fd0_0_c0' @tap.stop="handleJumpDiy"
						data-type="back" data-url="1">
						<text class='fu-iconfont2  personalData_fd0_0_c0_c0'>&#xE794;</text>
					</view>
					<view class='flex flex-wrap align-stretch justify-center'>
						<text class='personalData_fd0_0_c1_c0'>我的资料</text>
					</view>
					<view class='flex flex-wrap align-center justify-end personalData_fd0_0_c0'>
					</view>
				</view>

			</view>
			<view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>

			<view class="flex flex-direction flex-wrap align-stretch personalData_flex_1">
				<view class='flex flex-wrap align-center personalData_fd1_0'>
					<text class='personalData_fd1_0_c0'>头像</text>
					<view class="upload position-relative personalData_fd1_0_c1">
						<image class=" personalData_fd1_0_c1_image" mode="aspectFill" @tap="croppingUploadImage('avatar','avatar',user,user)" :src="user.avatar"></image>
					</view>
					<image class='personalData_fd1_0_c2' mode="aspectFit" :src='STATIC_URL+"81.png"'></image>
				</view>
				<view class='flex flex-wrap align-center justify-between personalData_fd1_1'>
					<text class='personalData_fd1_0_c0'>姓名</text>
					<benben-input class='flex-sub personalData_fd1_1_c1' type="text" :placeholder="`请输入昵称`"
						confirm-type="done" :maxlength="14" placeholder-style="color:#666666;font-size:32rpx"
						v-model="user.nickname" />
				</view>
				<view class='flex flex-wrap align-center justify-between personalData_fd1_1' @tap.stop="pickerDiy1702537416284=true">
					<text class='personalData_fd1_0_c0'>性别</text>
					<view class='flex flex-wrap align-center'>
						<text class='personalData_fd1_2_c1_c0'>{{sex}}</text>
						<image class='personalData_fd1_0_c2' mode="aspectFit" :src='STATIC_URL+"81.png"'></image>
					</view>
				</view>
				<view class='flex flex-wrap align-center justify-between personalData_fd1_1' @tap.stop="pickerDiy1656986153485=true">
					<text class='personalData_fd1_0_c0'>生日</text>
					<benben-input class='flex-sub personalData_fd1_1_c1' type="text" :placeholder="`请选择生日`"
						confirm-type="done" :maxlength="14" placeholder-style="color:#666666;font-size:32rpx"
						v-model="user.birthday" :disabled="true" />
				</view>
				<view class='flex flex-wrap align-center justify-between personalData_fd1_1'>
					<text class='personalData_fd1_0_c0'>部门</text>
					<benben-input class='flex-sub personalData_fd1_1_c1' type="text" :placeholder="`请输入部门`"
						confirm-type="done" :maxlength="14" placeholder-style="color:#666666;font-size:32rpx"
						v-model="user.depart_name" :disabled="true"/>
				</view>
			</view>
			
			<button class='personalData_fd1_5' @tap.stop="submitsFunc()">保存</button>

			<!--选择性别开始 -->
			<benben-picker ref="benbenWritePickerCodepicker2" :visible.sync="pickerDiy1702537416284" :label.sync='sex'
				:value.sync='user.gender' :options='sex_options' mode='selector' :mask-show='true' :timeout='true'
				:picker-height='88' default-type='value' :default-props='{"label":"name","value":"value"}'>
				<template #picker-header>
					<view class='flex flex-wrap align-center justify-between personalData_picker2_0'>
						<text class='personalData_picker2_0_c0'
							@tap="$refs.benbenWritePickerCodepicker2.cancel()">取消</text>
						<text class='personalData_picker2_0_c1'>选择性别</text>
						<text class='personalData_picker2_0_c2'
							@tap="$refs.benbenWritePickerCodepicker2.pickerConfirm()">确认</text>
					</view>
				</template>
			</benben-picker>
			<!--选择性别结束 -->

			<!--选择生日开始 -->
			<benben-picker ref="benbenWritePickerCodepicker3" :visible.sync="pickerDiy1656986153485"
				:value.sync='user.birthday' mode='date' :picker-height='88' :current='true' :mask-show='true'
				fields='day' :timeout='true' start-year='1950-01-01' end-year='现在'>
				<template #picker-header>
					<view class='flex flex-wrap align-center justify-between myInfo_picker2_0'>
						<text class='myInfo_picker2_0_c0' @tap="$refs.benbenWritePickerCodepicker3.cancel()">取消</text>
						<text class='myInfo_picker2_0_c1'>请选择生日</text>
						<text class='myInfo_picker2_0_c2'
							@tap="$refs.benbenWritePickerCodepicker3.pickerConfirm()">确定</text>
					</view>
				</template>
			</benben-picker>
			<!--选择生日结束 -->
		</view>
	</view>
</template>
<script>
	import UploadImage from '@/common/utils/upload-image.js'
	import {
		validate
	} from '@/common/utils/validate.js'

	export default {
		components: {},


		data() {
			return {
				"pickerDiy1702537416284": false,
				"pickerDiy1656986153485": false,
				"header_img": "",
				"user": {
					"invite_code": "",
					"address": "",
					"address_code": "",
					"hobby": "",
					"tags": "",
					"id": "",
					"userlevel_id": "",
					"mobile": "",
					"real_name": "",
					"avatar": "",
					"account": "",
					"email": "",
					"birthday": "",
					"gender": "",
					"create_time": "",
					"user_money": "",
					"freeze_money": "",
					"total_consumption_money": "",
					"score": "",
					"_mobile": "",
					"coupon": "",
					"collection_count": "",
					"browse_count": "",
					"total_money": "",
					"certified": "",
					"nickname": "",
					"is_pay_password": "",
					"follow_count": "",
					"is_close": "",
					"lastid": "",
					"userlevel_name": ""
				},
				"sex": "",
				"sex_options": [{
					"name": "保密",
					"value": "0",
					"image": ""
				}, {
					"name": "男",
					"value": "1",
					"image": ""
				}, {
					"name": "女",
					"value": "2",
					"image": ""
				}],
				"is_submit": false,
			};
		},
		computed: {
			themeColor() {
				return this.$store.getters.themeColor
			},

		},
		watch: {},
		onLoad(options) {
			this.queryUserInfoFunc()
		},
		onUnload() {

		},
		onReady() {

		},
		onShow() {

		},
		onHide() {

		},
		onResize() {

		},
		onPullDownRefresh() {

		},
		onReachBottom(e) {

		},
		onPageScroll(e) {

		},
		methods: {
			//裁剪图片上传
			croppingUploadImage(id, path, obj, obj1, fnName = false) {
				let self = this
				if (!obj) obj = this
				if (!obj1) obj1 = this
				let itemList = obj1[path] ? ['修改头像', '拍照', '从手机相册选择'] : ['拍照', '从手机相册选择']

				function imageCroppingCuccess() {
					uni.$once('image-cropping-success', (file) => {
						if (!file) return
						new UploadImage([file], {
							complete: (res) => {
								if (id) self.$set(obj, id, res[0].id)
								if (path) self.$set(obj1, path, res[0].path)
								if (fnName) self[fnName]()
							},
						})
					})
				}
				uni.showActionSheet({
					itemList: itemList,
					success: function(res) {
						if (res.tapIndex == 0 && obj1[path]) {
							uni.navigateTo({
								url: '/pages/benben-built-in/image-cropping/image-cropping?rectHeight=200&rectWidth=200&&myImgUrl=' +
									obj1[path],
								animationDuration: 0,
							})
							imageCroppingCuccess()
						}
						if ((res.tapIndex == 1 && obj1[path]) || (res.tapIndex == 0 && !obj1[path])) {
							uni.chooseImage({
								count: 1,
								sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
								sourceType: ['camera'], // 可以指定来源是相册还是相机，默认二者都有
								success: (res) => {
									// 跳转到图片裁切页面
									uni.navigateTo({
										url: `/pages/benben-built-in/image-cropping/image-cropping?rectHeight=200&rectWidth=200&fileType=${res.tempFiles[0].type}&myImgUrl=${res.tempFilePaths[0]}`,
										animationDuration: 0,
									})
									imageCroppingCuccess()
								},
							})
						}
						if ((res.tapIndex == 2 && obj1[path]) || (res.tapIndex == 1 && !obj1[path])) {
							uni.chooseImage({
								count: 1,
								sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
								sourceType: ['album'], // 可以指定来源是相册还是相机，默认二者都有
								success: (res) => {
									// 跳转到图片裁切页面
									uni.navigateTo({
										url: `/pages/benben-built-in/image-cropping/image-cropping?rectHeight=200&rectWidth=200&fileType=${res.tempFiles[0].type}&myImgUrl=${res.tempFilePaths[0]}`,
										animationDuration: 0,
									})
									imageCroppingCuccess()
								},
							})
						}
					},
					fail: function(res) {
						console.log(res.errMsg)
					},
				})
			},
			//获取用户详细信息
			async queryUserInfoFunc() {
				//请求方法
				//数据验证

				let datauser = await this.$api.get(global.apiUrls.post5c78c4772da97, {

				});

				if (datauser.data.code != 1) {
					this.$message.info(datauser.data.msg);
					return
				}
				let infouser = datauser.data;
				this.user = infouser.data

				if (this.user.gender == 0) {
					this.sex = '保密';
				} else if (this.user.gender == '1') {
					this.sex = '男';
				} else if (this.user.gender == '2') {
					this.sex = ' 女';
				}
			},
			//修改个人资料
			async submitsFunc() {
				if (this.is_submit) return;
				if (!validate(this.user.nickname, 'require')) {
					this.$message.info('请输入昵称');
					return false;
				}
				if (!this.user.birthday) {
					this.$message.info('请选择生日');
					return false;
				}
				//请求方法
				//数据验证
				this.is_submit = true;
				let data5cb54af125f1c = await this.$api.dbPost(global.apiUrls.post5cb54af125f1c, {
					avatar: this.user.avatar,
					nickname: this.user.nickname,
					gender: this.user.gender,
					birthday: this.user.birthday
				});
				if (data5cb54af125f1c.data.code != 1) {
					this.is_submit = false;
					this.$message.info(data5cb54af125f1c.data.msg);
					return
				}
				this.$message.info(data5cb54af125f1c.data.msg);
				setTimeout(() => {
					this.is_submit = false;
					uni.navigateBack();
				}, 800)
			}
		}
	};
</script>
<style lang="scss" scoped>
	.page {
		width: 100vw;
		overflow-x: hidden;
		min-height: calc(100vh - var(--window-bottom));
		background: #f6f7f9;
		background-size: 100% auto;
	}

	.personalData_flex_0 {
		background: #fff;
		width: 750rpx;
		height: 88rpx;
		overflow: hidden;
		z-index: 10;
		top: 0rpx;
		background-size: 100% auto !important;
	}

	.personalData_fd0_0_c1_c0 {
		font-size: 36rpx;
		font-weight: 500;
		color: #333;
		line-height: 88rpx;
	}

	.personalData_fd0_0_c0_c0 {
		font-size: 36rpx;
		color: #333;
	}

	.personalData_fd0_0_c0 {
		width: 120rpx;
	}

	.personalData_fd0_0 {
		padding: 0rpx 32rpx 0rpx 32rpx;
	}

	.personalData_flex_1 {
		background: #fff;
		margin: 32rpx 36rpx 0rpx 36rpx;
		border-radius: 16rpx;
	}
	.myInfo_picker2_0_c2 {
		color: #E60012;
		line-height: 40rpx;
		font-size: 32rpx;
		font-weight: 500;
	}
	
	.myInfo_picker2_0_c1 {
		font-size: 32rpx;
		font-weight: 400;
		color: #333333;
	}
	
	.myInfo_picker2_0_c0 {
		line-height: 40rpx;
		font-size: 32rpx;
		font-weight: 500;
		color: #BFBFBF;
	}
	
	.myInfo_picker2_0 {
		border-bottom: 1px solid #eee;
		background: #fff;
		padding: 0rpx 32rpx 0rpx 32rpx;
		line-height: 88rpx;
		border-radius: 25rpx 25rpx 0rpx 0rpx;
		background-size: 100% auto !important;
	}
	

	.personalData_fd1_5 {
		background: #E60012;
		font-size: 32rpx;
		color: var(--benbenFontColor3);
		line-height: 80rpx;
		height: 80rpx;
		margin: 60rpx auto 0rpx auto;
		width: 678rpx;
		border-radius: 16rpx;
	}

	.personalData_fd1_4 {
		background: #fff;
		background-size: 100% auto !important;
		padding: 40rpx 40rpx 40rpx 40rpx;
	}

	.personalData_fd1_3_c1 {
		color: #333333;
		font-size: 32rpx;
		font-weight: 400;
		line-height: 40rpx;
		margin: 0rpx 0rpx 0rpx auto;
	}

	.personalData_fd1_3_c0 {
		color: #333333;
		font-size: 32rpx;
		font-weight: 400;
		line-height: 40rpx;
	}

	.personalData_fd1_3 {
		border-bottom: 1px solid var(--benbenbdColor0);
		background: #fff;
		background-size: 100% auto !important;
		padding: 40rpx 40rpx 40rpx 40rpx;
	}

	.personalData_fd1_2_c1_c0 {
		color: var(--benbenFontColor1);
		font-size: 32rpx;
		text-align: right;
	}

	.personalData_fd1_1_c1 {
		text-align: right;
		font-size: 32rpx;
		font-weight: 400;
		color: rgba(51, 51, 51, 1);
		margin: 0rpx 0rpx 0rpx 24rpx;
	}

	.personalData_fd1_1 {
		border-bottom: 1px solid var(--benbenbdColor0);
		padding: 40rpx 40rpx 40rpx 40rpx;
	}

	.personalData_fd1_0_c2 {
		width: 22rpx;
		height: 32rpx;
		margin: 0rpx 0rpx 0rpx 16rpx;
	}

	.personalData_fd1_0_c1_image {
		width: 96rpx;
		height: 96rpx;
		border-radius: 48rpx;
	}

	.personalData_fd1_0_c1 {
		width: 100rpx;
		height: 100rpx;
		border-radius: 50rpx 50rpx 50rpx 50rpx;
		margin: 0rpx 0rpx 0rpx auto;
	}

	.personalData_fd1_0_c0 {
		font-size: 32rpx;
		font-weight: 400;
		color: #333333;
		line-height: 45rpx;
	}

	.personalData_fd1_0 {
		border-bottom: 1px solid var(--benbenbdColor0);
		padding: 25rpx 40rpx 25rpx 40rpx;
	}

	.personalData_picker2_0_c2 {
		color: #E60012;
		font-size: 28rpx;
	}

	.personalData_picker2_0_c1 {
		font-size: 32rpx;
		color: var(--benbenFontColor1);
	}

	.personalData_picker2_0_c0 {
		font-size: 28rpx;
		color: var(--benbenFontColor2);
	}

	.personalData_picker2_0 {
		border-bottom: 1px solid #eee;
		background: #fff;
		padding: 0rpx 32rpx 0rpx 32rpx;
		line-height: 88rpx;
		border-radius: 25rpx 25rpx 0rpx 0rpx;
		background-size: 100% auto !important;
	}
</style>